#include "Audio.h"

#include "Object/NewObject.h"

float RAudio::GetLength() const
{
    return PCMData.Num() / (double)(SampleRate * NumChannels * BitsPerSample / 8);
}

RAudioPtr RAudio::CreateAudio(
    RObject *InOwner, const TVector<uint8_t> &InPCMData, int64_t InNumChannels, int64_t InSampleRate, int64_t InBitsPerSample)
{
    RAudioPtr Audio = NewObject<RAudio>(InOwner);
    Audio->NumChannels = InNumChannels;
    Audio->SampleRate = InSampleRate;
    Audio->BitsPerSample = InBitsPerSample;
    Audio->ByteRate = InSampleRate * InNumChannels * InBitsPerSample / 8;
    Audio->BlockAlign = InNumChannels * InBitsPerSample / 8;
    Audio->PCMData = InPCMData;

    return Audio;
}

